/**
 * Created by holly on 2017/8/11.
 */

//1、创建构造函数
function Ball(option) {
    this._init(option);
}

//2、设置原型对象
Ball.prototype = {
    constructor: Ball,
    //设置初始方法
    _init: function (option) {
        option = option || {};
        //圆心坐标
        this.x = option.x || 0;
        this.y = option.y || 0;
        //半径
        this.r = option.r || 0;

        //颜色
        this.fillColor = option.fillColor || 'black';
        this.strokeColor = option.strokeColor || 'black';

        //描边宽度
        this.strokeWidth = option.strokeWidth || 1;

        //文字
        this.text = option.text;
        this.textColor = option.textColor || 'white';
    },
    //绘制方法
    render: function (layer) {
        //创建组
        this.group = new Konva.Group({
            x: this.x,
            y: this.y
        });
        layer.add(this.group);

        //绘制圆
        var circle = new Konva.Circle({
            radius: this.r,
            fill: this.fillColor,
            stroke: this.strokeColor,
            strokeWidth: this.strokeWidth
        });
        this.group.add(circle);

        //绘制文字
        var text = new Konva.Text({
            x: -this.r,
            y: -8,
            text: this.text,
            width:this.r*2,
            fontSize: 18,
            fill: this.textColor,
            align:'center'
        });
        this.group.add(text);

    }
};